package com.woniuxy.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 固定大小线程池
 * <P> Date: 2022/4/10:16:31
 * <P> Description:
 */
@Slf4j(topic = "c.ThreadPoolTest02")
public class ThreadPoolTest02 {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(2
                , new ThreadFactory() {
                    private  final AtomicInteger t = new AtomicInteger(1);

                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r, "mypool_t" + t.getAndIncrement());
                    }
                });

        pool.execute(() -> {
            log.debug("1");
        });

        pool.execute(() -> {
            log.debug("2");
        });

        pool.execute(() -> {
            log.debug("3");
        });

    }
}
